﻿@using System.Collections
@using GigaSite.Web.Classes
@using GigaSite.Web.Models
@{
    ViewBag.Title = "Моя визитница";
    var itemsPerPage = (int)ViewBag.itemsPerPage;
    var currentPage = (int) ViewBag.currentPage;
    var filterLetter = (string) ViewBag.filterLetter;
    var totalCardsCount = (int) ViewBag.totalCardsCount;
    var totalCardsUnfiltredCount = (int) ViewBag.totalCardsUnfiltredCount;
    var companyCardsCount = (int) ViewBag.companyCardsCount;
    var personalCardsCount = (int) ViewBag.personalCardsCount;
    var totalPagesCount = MathHelper.PagesCount(totalCardsCount,itemsPerPage);
    var companyPagesCount = MathHelper.PagesCount(companyCardsCount, itemsPerPage);
    var personalPagesCount = MathHelper.PagesCount(personalCardsCount, itemsPerPage);
}

<script language="javascript" type="text/javascript" src="@Url.Content("~/Scripts/Common/ajaxItemsGrid.js")"></script>

<div id="page-cards">
    <div id="cards" class="section">
        <div class="sectionTitle">
            <span>> Моя визитница</span> <span class="sectionCounter">(@totalCardsUnfiltredCount)</span>
            <div class="triangle"></div>
        </div>
        <div class="sectionContent">
            <ul class="nav nav-tabs sectionMenu">
                <li class="active"><a href="#All" data-toggle="tab">Все</a></li>
                <li><a href="#Companies" data-toggle="tab">Компании</a></li>
                <li><a href="#Specialists" data-toggle="tab">Специалисты</a></li>
            </ul>

            <div class="insideSectionContainer">
                
                <div class="alphabet">
                    <span class="rusEng">
                        <span class="rus activeLang" lang="ru">Рус</span> / <span class="eng" lang="en">Eng</span>
                    </span>
                    <span class="abc" lang="all">
                        <span letter="" class="abcLetter">Все</span>
                    </span>
                    <span class="abc" lang="en">
                        <span letter="ALL" class="abcLetter all">Все</span>
                        <span letter="A" class="abcLetter">A</span>
                        <span letter="B" class="abcLetter">B</span>
                        <span letter="C" class="abcLetter">C</span>
                        <span letter="D" class="abcLetter">D</span>
                        <span letter="E" class="abcLetter">E</span>
                        <span letter="F" class="abcLetter">F</span>
                        <span letter="G" class="abcLetter">G</span>
                        <span letter="H" class="abcLetter">H</span>
                        <span letter="I" class="abcLetter">I</span>
                        <span letter="J" class="abcLetter">J</span>
                        <span letter="K" class="abcLetter">K</span>
                        <span letter="L" class="abcLetter">L</span>
                        <span letter="M" class="abcLetter">M</span>
                        <span letter="N" class="abcLetter">N</span>
                        <span letter="O" class="abcLetter">O</span>
                        <span letter="P" class="abcLetter">P</span>
                        <span letter="Q" class="abcLetter">Q</span>
                        <span letter="R" class="abcLetter">R</span>
                        <span letter="S" class="abcLetter">S</span>
                        <span letter="T" class="abcLetter">T</span>
                        <span letter="U" class="abcLetter">U</span>
                        <span letter="V" class="abcLetter">V</span>
                        <span letter="W" class="abcLetter">W</span>
                        <span letter="X" class="abcLetter">X</span>
                        <span letter="Y" class="abcLetter">Y</span>
                        <span letter="Z" class="abcLetter">Z</span>
                    </span>
                    <span class="abc abcActive" lang="ru">
                        <span letter="ALL" class="abcLetter all">Все</span>
                        <span letter="А" class="abcLetter">А</span>
                        <span letter="Б" class="abcLetter">Б</span>
                        <span letter="В" class="abcLetter">В</span>
                        <span letter="Г" class="abcLetter">Г</span>
                        <span letter="Д" class="abcLetter">Д</span>
                        <span letter="Е" class="abcLetter">Е</span>
                        <span letter="Ж" class="abcLetter">Ж</span>
                        <span letter="З" class="abcLetter">З</span>
                        <span letter="И" class="abcLetter">И</span>
                        <span letter="К" class="abcLetter">К</span>
                        <span letter="Л" class="abcLetter">Л</span>
                        <span letter="М" class="abcLetter">М</span>
                        <span letter="Н" class="abcLetter">Н</span>
                        <span letter="О" class="abcLetter">О</span>
                        <span letter="П" class="abcLetter">П</span>
                        <span letter="Р" class="abcLetter">Р</span>
                        <span letter="С" class="abcLetter">С</span>
                        <span letter="Т" class="abcLetter">Т</span>
                        <span letter="У" class="abcLetter">У</span>
                        <span letter="Ф" class="abcLetter">Ф</span>
                        <span letter="Х" class="abcLetter">Х</span>
                        <span letter="Ч" class="abcLetter">Ч</span>
                        <span letter="Щ" class="abcLetter">Щ</span>
                        <span letter="Ы" class="abcLetter">Ы</span>
                        <span letter="Э" class="abcLetter">Э</span>
                        <span letter="Ю" class="abcLetter">Ю</span>
                        <span letter="Я" class="abcLetter">Я</span>
                    </span>
                </div>
                
                
                <div class="tab-content">
                    @* Все визитки *@    
                    <div class="tab-pane active" id="All" data-currentPage="@currentPage" data-totalPages="@totalPagesCount" data-totalCards="@totalCardsCount" data-itemsPerPage="@itemsPerPage">
                        <div class="tabHeader">
                            <span class="gridHeader">Все визитки</span>
                            <div class="fr">
                                <span class="prevNext">
                                    <span class="prev">< пред.</span>
                                    <span class="bddv"></span>
                                    <span class="next">след. ></span>
                                </span>
                            </div>
                        </div>
                        
                        <div class="overview">
                            @{
                                Html.RenderAction("BusinessCards", new {filter = "all", itemsPerPage = itemsPerPage, currentPage = currentPage});   
                            }
                        </div>

                        <div class="paginator">
                            <span class="pages">Страница <span class="current currentPage">1</span> / <span class="totalPages">@totalPagesCount</span></span>
                            <span class="showed">Показано <span class="current itemsShows"><span class="startItem">1</span>-<span class="endItem">@(itemsPerPage > totalCardsCount ? totalCardsCount : itemsPerPage)</span></span> / <span class="totalCards">@totalCardsCount</span></span>
                            <div class="fr">
                                <span class="prevNext">
                                    <span class="prev">< пред.</span>
                                    <span class="bddv"></span>
                                    <span class="next">след. ></span>
                                </span>
                            </div>
                        </div>
                    </div>
                    
                    @* Визитки компаний *@
                    <div class="tab-pane" id="Companies" data-currentPage="@currentPage" data-totalPages="@companyPagesCount" data-totalCards="@companyCardsCount" data-itemsPerPage="@itemsPerPage">
                        <div class="tabHeader">
                            <span class="gridHeader">Компании</span>
                            <div class="fr">
                                <span class="prevNext">
                                    <span class="prev">< пред.</span>
                                    <span class="bddv"></span>
                                    <span class="next">след. ></span>
                                </span>
                            </div>
                        </div>

                        @{
                            Html.RenderAction("BusinessCards", new {filter = "company", itemsPerPage = itemsPerPage, currentPage = currentPage});   
                        }

                        <div class="paginator">
                            <span class="pages">Страница <span class="current currentPage">1</span> / <span class="totalPages">@companyPagesCount</span></span>
                            <span class="showed">Показано <span class="current itemsShows"><span class="startItem">1</span>-<span class="endItem">@(itemsPerPage > companyCardsCount ? companyCardsCount : itemsPerPage)</span></span> / <span class="totalCards">@companyCardsCount</span></span>
                            <div class="fr">
                                <span class="prevNext">
                                    <span class="prev">< пред.</span>
                                    <span class="bddv"></span>
                                    <span class="next">след. ></span>
                                </span>
                            </div>
                        </div>
                    </div>
                    
                    @* Визитки специалистов *@
                    <div class="tab-pane" id="Specialists"  data-currentPage="@currentPage" data-totalPages="@personalPagesCount" data-totalCards="@personalCardsCount" data-itemsPerPage="@itemsPerPage">
                        <div class="tabHeader">
                            <span class="gridHeader">Специалисты</span>
                            <div class="fr">
                                <span class="prevNext">
                                    <span class="prev">< пред.</span>
                                    <span class="bddv"></span>
                                    <span class="next">след. ></span>
                                </span>
                            </div>
                        </div>
                        
                        <div class="overview">
                            @{
                                Html.RenderAction("BusinessCards", new { filter = "specialist", itemsPerPage = itemsPerPage, currentPage = currentPage });   
                            }
                        </div>

                        <div class="paginator">
                            <span class="pages">Страница <span class="current currentPage">1</span> / <span class="totalPages">@personalPagesCount</span></span>
                            <span class="showed">Показано <span class="current itemsShows"><span class="startItem">1</span>-<span class="endItem">@(itemsPerPage > personalCardsCount ? personalCardsCount : itemsPerPage)</span></span> / <span class="totalCards">@personalCardsCount</span></span>
                            <div class="fr">
                                <span class="prevNext">
                                    <span class="prev">< пред.</span>
                                    <span class="bddv"></span>
                                    <span class="next">след. ></span>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script language="javascript" type="text/javascript">
    var allCardsGrid = new AjaxItemsGridLoader($("#All"), "@Url.Action("BusinessCards","Account")", "all");
    var companyCards = new AjaxItemsGridLoader($("#Companies"), "@Url.Action("BusinessCards","Account")", "company");
    var specialistCardsGrid = new AjaxItemsGridLoader($("#Specialists"), "@Url.Action("BusinessCards","Account")", "specialist");
    
    // Обработка переключения языка
    var filterLetter = '@filterLetter'.toUpperCase();
    //var filterLetter = 'A'.toUpperCase();
    $(".rusEng > span").click(function() {
        $(".abc").hide();
        $(".rusEng > span").removeClass("activeLang");
        var selector = ".alphabet span[lang='" + $(this).attr("lang") + "']";
        $(selector).show();
        $(this).addClass("activeLang");
    });
    // установка фильтра по умолчанию
    var engLangRe = /[A-Z]{1,}/gi ;
    var rusLangRe = /[А-Я]{1,}/gi ;
    if (engLangRe.exec(filterLetter)) {
        $(".alphabet span[lang='en']").click();
    }
    if (rusLangRe.exec(filterLetter)) {
        $(".alphabet span[lang='ru']").click();
    }
    // Установка выбранной буквы на фильтре
    var letterSelector = selector = ".abc span[letter='" + filterLetter + "']";
    $(letterSelector).addClass("abcLetterActive");
    if (filterLetter != "") {
        $(".alphabet .all").show();
    }

    // Установка перехода по буквам
    $("span[letter]").click(function(e) {
        var letter = $(this).attr("letter");
        if (letter == "ALL") {
            window.location.href = "@Url.Action("Cards")";
        }
        else {
            window.location.href = "@Url.Action("Cards")?filterLetter=" + letter;
        }
    });
</script>